home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / text / hyper / ADtoHT2_0.lha / ProcessDir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  2.7 KB  |  101 lines

  1. #ifndef DOS_DOSASL_H
  2. #include <dos/dosasl.h>
  3. #endif
  4.  
  5. #include <proto/dos.h>
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <errno.h>
  10.  
  11. /************************************************************************/
  12.  
  13. #include "main.h"
  14. #include "ProcessDir.h"
  15.  
  16. /************************************************************************/
  17.  
  18. struct MyAnchorPath __ALIGN(AnchorPath);
  19.  
  20. int CallMatchEnd;
  21.  
  22. /************************************************************************/
  23. /*                                                                      */
  24. /* Read a directory, recursively, and call Function(Filename).          */
  25. /*                                                                      */
  26. /************************************************************************/
  27.  
  28. void
  29. ProcessDir1 (int Directory, char *FilePattern, void (*Function) (char *))
  30.  
  31. {
  32.   char Pattern[32];
  33.   long Error;
  34.  
  35.   puts ("");
  36.  
  37.   CurrentDir (Dirs[Directory]);
  38.   ParsePatternNoCase (FilePattern, Pattern, sizeof (Pattern));
  39.   AnchorPath.AnchorPath.ap_Flags = APF_DOWILD;
  40.   AnchorPath.AnchorPath.ap_Strlen = 1024;
  41.   AnchorPath.AnchorPath.ap_BreakBits = SIGBREAKF_CTRL_C;
  42.  
  43.   CallMatchEnd = TRUE;
  44.   Error = MatchFirst ("", &AnchorPath.AnchorPath);
  45.   while (!Error)
  46.     {
  47.       if (AnchorPath.AnchorPath.ap_Flags & APF_DIDDIR)
  48.     {
  49.       AnchorPath.AnchorPath.ap_Flags &= ~APF_DIDDIR;
  50.     }
  51.       else
  52.     {
  53.       if (AnchorPath.AnchorPath.ap_Info.fib_DirEntryType > 0)
  54.         {
  55.           AnchorPath.AnchorPath.ap_Flags |= APF_DODIR;
  56.         }
  57.       else
  58.         {
  59.           if (MatchPatternNoCase (Pattern, AnchorPath.AnchorPath.ap_Info.fib_FileName))
  60.         {
  61.           printf ("Reading %s\n", AnchorPath.AnchorPath.ap_Buf);
  62.           Function (AnchorPath.AnchorPath.ap_Buf);
  63.         }
  64.         }
  65.     }
  66.       Error = MatchNext (&AnchorPath.AnchorPath);
  67.     }
  68.   MatchEnd (&AnchorPath.AnchorPath);
  69.   CallMatchEnd = FALSE;
  70.   if (Error != ERROR_NO_MORE_ENTRIES)
  71.     {
  72.       errno=Error;
  73.       perror (Arguments.Dirs[Directory]);
  74.       CloseAll (RETURN_ERROR);
  75.     }
  76. }
  77.  
  78. /************************************************************************/
  79. /*                                                                      */
  80. /* Run second pass for a directory.                                     */
  81. /*                                                                      */
  82. /************************************************************************/
  83.  
  84. void
  85. ProcessDir2 (int Directory, struct AVLTree *DirTree, void (*Function) (struct AnyNode *))
  86.  
  87. {
  88.   struct AVLNode *CurrentNode;
  89.   struct AVLStateInfo StateInfo;
  90.  
  91.   puts ("");
  92.  
  93.   CurrentDir (Dirs[Directory]);
  94.  
  95.   AVL_InitTraversal (DirTree, &StateInfo);
  96.   while ((CurrentNode = AVL_InOrder (&StateInfo)))
  97.     {
  98.       Function ((struct AnyNode *) CurrentNode);
  99.     }
  100. }
  101.